package com.zhangxun.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangxun.domain.Prod;
import com.zhangxun.domain.ProdComm;
import com.zhangxun.service.ProdCommService;
import com.zhangxun.vo.ProdCommData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api
@RestController
@RequestMapping("/prod/prodComm")
public class ProdCommController {

    @Autowired
    private ProdCommService ProdCommService;


    @PreAuthorize("hasAuthority('prod:prodComm:page')")
    @ApiOperation("分页查询品论数据接口")
    @GetMapping("page")
    public Page<ProdComm> page(Page<ProdComm> page,ProdComm prodComm){

     page = ProdCommService.selectPageAnCondition(page,prodComm);
     return page;
    }

    @GetMapping("/prodComm/prodCommData")
    @ApiOperation("通过商品id查询商品评论数据的接口")
    public ResponseEntity<ProdCommData> prodCommData(Long prodId){

        ProdCommData ProdCommData = ProdCommService.selectCommNumDetails(prodId);
        return ResponseEntity.ok(ProdCommData);
    }

    @GetMapping("/prodComm/prodCommPageByProd")
    @ApiOperation("分页查询对应条件的商品评论")
    public Page<ProdComm> prodCommPageByProd(Page<ProdComm> page, Long prodId, Integer evaluate){
      page =  ProdCommService.pageByCondition(page,prodId,evaluate);

      return page;
    }
}
